//
//  MJDIYBackFooter.m
//  MJRefreshExample
//
//  Created by MJ Lee on 15/6/13.
//  Copyright © 2015年 小码哥. All rights reserved.
//

#import "MJDIYBackFooter.h"

@interface MJDIYBackFooter()
@property (weak, nonatomic) UILabel *label;
@property (weak, nonatomic) UIImageView *logo;
@property (weak, nonatomic) UIActivityIndicatorView *loading;
@end

@implementation MJDIYBackFooter
#pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置（比如添加子控件）
- (void)prepare {
    [super prepare];
    
    // 设置控件的高度
    self.mj_h = 70.0;
    
    // 添加label
    UILabel *label = [[UILabel alloc] init];
    label.textColor = RGBColor(177, 177, 177);
    label.font = [UIFont boldSystemFontOfSize:12.0];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    self.label = label;
    if ([[BDAccountManagerModel shareInstance].langage isEqualToString:@"zang"]) {
        self.label.numberOfLines = 0;
        self.label.font = [UIFont fontWithName:@"Bzdbt" size:9.0];
    }
    
    // logo
    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noData"]];
    logo.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:logo];
    self.logo = logo;
    
    // loading
    UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [self addSubview:loading];
    self.loading = loading;
}

#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews {
    [super placeSubviews];
    
    self.logo.bounds = CGRectMake(0, 0, self.bounds.size.width, 30.0);
    self.logo.center = CGPointMake(self.mj_w * 0.5, 30.0);
    
    self.label.frame = CGRectMake(0, 55.0, self.bounds.size.width, 10.0);
    
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12.0]};
    NSString *str = NSLocalizedString(@"Loading ...", nil);
    CGSize textSize = [str boundingRectWithSize:CGSizeMake(320.0, CGFLOAT_MAX) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    
    self.loading.x = self.bounds.size.width / 2 - textSize.width / 2 - 23.0;
    self.loading.y = 55.0;
}

#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change {
    [super scrollViewContentOffsetDidChange:change];
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change {
    [super scrollViewContentSizeDidChange:change];
    
}

#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change {
    [super scrollViewPanStateDidChange:change];
    
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state {
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
            [self.loading stopAnimating];
            self.label.text = NSLocalizedString(@"Pull down to refresh", nil);
            break;
        case MJRefreshStatePulling:
            [self.loading stopAnimating];
            self.label.text = NSLocalizedString(@"Release to refresh", nil);
            break;
        case MJRefreshStateRefreshing:
            [self.loading startAnimating];
            self.label.text = NSLocalizedString(@"Loading ...", nil);
            break;
        case MJRefreshStateNoMoreData:
            [self.loading stopAnimating];
            self.label.text = NSLocalizedString(@"loaded all data", nil);
        default:
            break;
    }
}

#pragma mark 监听拖拽比例（控件被拖出来的比例）
- (void)setPullingPercent:(CGFloat)pullingPercent {
    [super setPullingPercent:pullingPercent];
}

@end
